
import java.util.Scanner;

public class youlishu {
    private static Scanner sc;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in


        );
        int v1,v2,i;
        Rational T1;
        Rational T2;
        Rational T3=new Rational();
        v1=sc.nextInt();
        v2=sc.nextInt();
        T1=new Rational(v1, v2);
        v1=sc.nextInt();
        v2=sc.nextInt();
        T2=new Rational(v1, v2);
        Rational.Add(T1, T2, T3);
        System.out.println(T3.getv1()+" "+T3.getv2());
        Rational.Multiply(T1, T2, T3);
        System.out.println(T3.getv1()+" "+T3.getv2());
        i = sc.nextInt();
        Rational.GetRational(T1, i);
        System.out.println(Rational.GetRational(T1, i));
        System.out.println("201621123021简卓林");
    }



}
class Rational{
    private int v1;
    private int v2;

    public void buildv1(int v1){
        this.v1=v1;
    }
    public int getv1(){
        return v1;
    }
    public void buildv2(int v2){
        this.v2=v2;
    }
    public int getv2(){
        return v2;
    }
    public  Rational(int v1, int v2)
    {
        this.v1=v1;
        this.v2=v2;
    }
    public  Rational(){

    }
    public static int GetRational(Rational T, int i) {
        if(i==1)
            return T.getv1();
        else
            return T.getv2();
    }

    public static void Multiply(Rational T1, Rational T2, Rational T3) {
        int t;
        T3.buildv2(T1.getv2()*T2.getv2());
        T3.buildv1(T1.getv1()*T2.getv1());
        t=Gcd(T3.getv2(),T3.getv1());
        T3.buildv2(T3.getv2()/t);
        T3.buildv1(T3.getv1()/t);

    }
    public static void Add(Rational T1, Rational T2, Rational T3) {
        int temp;
        T3.buildv2(T1.getv2()*T2.getv2());
        T3.buildv1(T1.getv1()*T2.getv2()+T2.getv1()*T1.getv2());
        temp=Gcd(T3.getv2(), T3.getv1());
        T3.buildv2(T3.getv2()/temp);
        T3.buildv1(T3.getv1()/temp);

    }
    public static int Gcd(int x,int y)
    {
        int temp;
        while(x%y!=0)
        {
            temp=y;
            y=x%y;
            x=temp;
        }
        return y;
    }

}
